define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'bootstrap-table-jumpto'], function ($, undefined, Backend, Table, Form, Jumpto) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'salesman/statistics/index' + location.search,
                    add_url: 'salesman/statistics/add',
                    edit_url: 'salesman/statistics/edit',
                    del_url: 'salesman/statistics/del',
                    multi_url: 'salesman/statistics/multi',
                    table: 'salesman_register',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport: false,
                showJumpto: true,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: '用户ID'},
                        {field: 'name', title: '姓名', operate: 'like'},
                        {field: 'goods.name', title: '牛名称', operate: 'like'},
                        {field: 'mobile', title: '电话', operate: 'like'},
                        {field: 'num', title: '订购数量', sortable: true, operate: false},
                        {field: 'company_text', title: '牛场',operate: 'like'},
                        {field: 'address_text', title: '地址',operate: false,cellStyle:Controller.api.css.area},
                        {field: 'remark', title: '备注',operate: false,cellStyle:Controller.api.css.area},
                        {field: 'type', title: __('Type'), searchList: {'0' : '待处理', '1' :'已安排', '2' :'拒绝', '3':'待定'}, formatter: Table.api.formatter.normal},
                    ]
                ],
                queryParams: function (params) {
                    //如果希望追加搜索条件,可使用
                    var filter = params.filter ? JSON.parse(params.filter) : {};
                    var op = params.op ? JSON.parse(params.op) : {};
                    filter.register_id = Config.register_id;
                    op.register_id = '=';
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            css: {
                str: function () {
                    return {
                        css: {
                            'max-width': '100px',
                            'max-height': '150px'
                        }
                    };
                },
                address: function () {
                    return {
                        css: {
                            'max-width': '100px',
                            'max-height': '150px'
                        }
                    };
                }
            }
        }
    };
    return Controller;
});